<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-position="left"
      label-width="120px"
      v-loading="formLoading"
    >
      <el-form-item label="信息模态" prop="text1">
        <el-select
          v-model="formData.text1"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="item in selectList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="调用策略登记" prop="text2">
        <el-select
          v-model="formData.text2"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="item in selectList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="验证集调用策略" prop="text3">
        <el-select
          v-model="formData.text3"
          placeholder="请选择"
          clearable
          class="!w-240px"
        >
          <el-option
            v-for="item in selectList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false" type="primary">取消</el-button>
      <el-button @click="submitForm" type="primary">确定</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
/** 查看失败原因 弹窗 */
defineOptions({ name: 'ValidationsetAllocation' })

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = '验证集分配' // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref({
  id: 0,
  text1: '',
  text2: '',
  text3: ''
})
const formRules = reactive({
  text1: [{ required: true, message: '描述原因不能为空', trigger: 'blur' }],
  text2: [{ required: true, message: '描述原因不能为空', trigger: 'blur' }],
  text3: [{ required: true, message: '描述原因不能为空', trigger: 'blur' }],
})
/** 打开弹窗 */
const open = async (id: number) => {
  resetForm()
  dialogVisible.value = true
  formData.value = {
    id,
    text1: '',
    text2: '',
    text3: ''
  }
}
const selectList = [
  { label: '11', value: 11}
]
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

const formRef = ref() // 表单 Ref
/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  // 校验表单
  await formRef.value.validate()
  // 提交请求
  formLoading.value = true
  try {
    // let data = formData.value as unknown as EvaluationTaskVO
    // await EvaluationTaskApi.createEvaluationTask(data)
    // message.success('驳回成功')
    dialogVisible.value = false
    // 发送操作成功的事件
    emit('success')
  } finally {
    formLoading.value = false
  }
}
/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: 0,
    text1: '',
    text2: '',
    text3: ''
  }
  formRef.value?.resetFields()
}
</script>
<style lang="scss" scoped>
.issues-wrap {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 30px;
  margin-bottom: 30px;
  margin-right: 30px;
  .err-title {
    width: 90px;
    font-size: 14px
  }
  .err-content{
    flex: 1;
  }
}
</style>